package com.zy.service.bs.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.bs.IntegralDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.bs.Integral;
import com.zy.pojo.query.bs.IntegralQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.bs.IntegralService;
import com.zy.utils.DateUtil;

@Service("integralService")
public class IntegralServiceImpl extends BaseServiceImpl<Integral> implements IntegralService {

	@Autowired
	private IntegralDao integralDao;

	@Override
	public PageVo pageIntegral(IntegralQuery integralQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.integralDao.countIntegral(integralQuery), this.integralDao.listIntegral(integralQuery, start, limit));
	}

	@Override
	public void saveIntegral(Integral integral) {
		long time = DateUtil.getTime();
		this.integralDao.save(integral);
	}
	
	@Override
	public void updateIntegral(Integral integral) {
		this.integralDao.updateByPrimaryKeySelective(integral);
	}

	@Override
	public void removeIntegral(long id) {
		try {
			this.integralDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			Integral integral = new Integral();
			integral.setId(id);

			this.integralDao.updateByPrimaryKeySelective(integral);
		}
	}

	@Override
	public void recover(long id) {
		Integral integral = new Integral();
		integral.setId(id);

		this.integralDao.updateByPrimaryKeySelective(integral);
	}

}
